<script type="text/javascript">//<![CDATA[

	XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "services", "smartinfo", "status")%>', null,
		function(x, st)
		{
			var tb = document.getElementById('smart_status_table');
			if (st && tb)
			{
				/* clear all rows */
				while( tb.rows.length > 1 )
					tb.deleteRow(1);

				for( var i = 0; i < st.length; i++ )
				{
					var tr = tb.insertRow(-1);
						tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
					var td = null
          
					tr.insertCell(-1).innerHTML = st[i].name;
					tr.insertCell(-1).innerHTML = st[i].model;
					tr.insertCell(-1).innerHTML = st[i].size;
					if(st[i].status == 'Failed')
					{
            td = tr.insertCell(-1);
            td.innerHTML = "<font color='black'>" + st[i].status + "</font>"
            td.style.cssText = "background-color:red !important;";
					}
					else
					{
            tr.insertCell(-1).innerHTML = st[i].status;
					}
					
					if(st[i].status == 'Failed' || st[i].status == 'OK')
					{
            td = tr.insertCell(-1);
            td.innerHTML = "<input class='cbi-button cbi-button-find' type='button' value=' <%:Show%> ' onclick='show_detail(\"" + st[i].name + "\");' />"
					}
					else
					{
            tr.insertCell(-1).innerHTML = "---";
					}
				}

				if( tb.rows.length == 1 )
				{
					var tr = tb.insertRow(-1);
						tr.className = 'cbi-section-table-row';

					var td = tr.insertCell(-1);
						td.colSpan = 4;
						td.innerHTML = '<em><br /><%:No storage device to monitor.%></em>';
				}
			}
		}
	);
//]]></script>

<script type="text/javascript">
  function show_detail(dev)
  {
    window.open('<%=luci.dispatcher.build_url("admin", "services", "smartinfo", "smartdetail")%>/' + dev,
      'newwindow','height=480,width=800,top=100,left=200,toolbar=no,menubar=no,scrollbars=yes, resizable=no,location=no, status=no')
  }
</script>

<fieldset class="cbi-section">
	<legend><%:S.M.A.R.T Status%></legend>
	<table class="cbi-section-table" id="smart_status_table">
		<tr class="cbi-section-table-titles">
			<th class="cbi-section-table-cell"><%:Device%></th>
			<th class="cbi-section-table-cell"><%:Model%></th>
			<th class="cbi-section-table-cell"><%:Size%></th>
			<th class="cbi-section-table-cell"><%:Status%></th>
			<th class="cbi-section-table-cell"><%:Detail%></th>
		</tr>
		<tr class="cbi-section-table-row">
			<td colspan="4"><em><br /><%:Collecting data...%></em></td>
		</tr>
	</table>
</fieldset>
